const path=require("path");
const HtmlWebpackPlugin=require("html-webpack-plugin");
const CopyWebpackPlugin=require("copy-webpack-plugin");
module.exports={
    mode:"production",
    entry:path.resolve(__dirname,"../src/index.js"),
    output:{
        path:path.resolve(__dirname,"../build"),
        filename:"./js/build.js",
        publicPath:"/"
    },
    plugins:[
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname,"../public/index.html"),
            filename:"index.html",
            minify:{
                collapseWhitespace:true,
                keepClosingSlash:true,
                removeComments:true,
                removeRedundantAttributes:true,
                removeScriptTypeAttributes:true,
                removeStyleLinkTypeAttributes:true,
                useShortDoctype:true
            }
        }),
        new CopyWebpackPlugin({
            patterns:[{
                from:path.resolve(__dirname,"../public"),
                to:"public",
                globOptions:{
                    ignore:["**/index.html"]
                }
            }]
        })
    ],
    module:{
        rules:[
                 {
            test: /\.ejs$/i,
            loader: "ejs-loader",
            options:{
                variable:"data"
            }
        },{
            test: /\.css$/i,
            use: ["style-loader","css-loader"],
        }
        ]
    },
    resolve:{
        alias:{
            $v:path.resolve(__dirname,"../src/views")
        },
        extensions:[".js",".json",".ejs"]
    }
}